package cn.wolfcode.trip.base.domain;

import cn.wolfcode.trip.base.util.DateUtil;
import com.alibaba.druid.support.json.JSONUtils;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.*;
import org.springframework.format.annotation.DateTimeFormat;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

@Setter
@Getter
@ToString
@AllArgsConstructor
@NoArgsConstructor
public class Daily extends BaseDomain{

    public static final Integer TYPE_NORMAL = 1;//美图美文
    public static final Integer TYPE_HOT = 2;//美图秀秀

    public String getTypeString(){
        if(type==TYPE_NORMAL){
            return "美图美文";
        }else if(type==TYPE_HOT){
            return "美图秀秀";
        }
        return "";
    }

    //封面
    private String coverUrl;
    //标题
    private String title;
    //副标题
    private String subTitle;
    //发布时间
    @JsonFormat(pattern = "yyyy-MM-dd",timezone = "GMT-8")
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    private Date releaseTime;
    //收藏时间
    @JsonFormat(pattern = "yyyy-MM-dd",timezone = "GMT-8")
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    private Date collectionTime;
    //分类
    private Integer type;
    //作者
    private String author;
    //收藏
    private Integer collection;
    //关联用户
    private User user;
    //关联日报的内容
    private DailyContent dailyContent;

    public String getJSONString(){
        Map<String,Object> map = new HashMap<String,Object>();
        map.put("id",getId() );
        map.put("coverUrl",coverUrl );
        map.put("title",title );
        map.put("subTitle",subTitle );
        map.put("releaseTime", DateUtil.formatDate(releaseTime));
        map.put("type",type );
        map.put("author",author );
        if(dailyContent!=null){
            map.put("contentId",dailyContent.getId() );
            map.put("content",dailyContent.getContent());
        }
        return JSONUtils.toJSONString(map);
    }
}
